package com.warm.androidstudy.view.room.model;

import androidx.room.Room;

import com.warm.androidstudy.MyApplication;

public class DBInstance {
    //private static final String DB_NAME = "/sdcard/LianSou/room_test.db";
    private static final String DB_NAME = "room_test";
    private static AppDataBase appDataBase;
    public static AppDataBase getInstance(){
        if (appDataBase==null){
            synchronized (DBInstance.class){
                if (appDataBase==null){
                    appDataBase = Room.databaseBuilder(MyApplication.getInstance(),AppDataBase.class,DB_NAME)
                            //下面注释表示容许主线程进行数据库操做，可是不推荐这样作。
                            //我这里是为了Demo展现，稍后会结束和LiveData和RxJava的使用
                            .allowMainThreadQueries()
                            .build();
                }
            }
        }
        return appDataBase;
    }

}
